﻿using Microsoft.EntityFrameworkCore;
using Domain;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure
{
    public class DataDbContext : DbContext
    {
        private readonly AuditableEntitySaveChangesInterceptor _auditableEntitySaveChangesInterceptor;

        public DataDbContext(
            DbContextOptions options,
            AuditableEntitySaveChangesInterceptor auditableEntitySaveChangesInterceptor) 
            : base(options)
        {
            _auditableEntitySaveChangesInterceptor = auditableEntitySaveChangesInterceptor;
        }

        // 数据库表集合
        public DbSet<TraceabilityInfo> TraceabilityInfos { get; set; }
        public DbSet<BreedingInfo> BreedingInfos { get; set; }
        public DbSet<HealthCareInfo> HealthCareInfos { get; set; }
        public DbSet<EnterpriseInfo> EnterpriseInfos { get; set; }
        public DbSet<ImageInfo> ImageInfos { get; set; }
        public DbSet<SlaughterInfo> SlaughterInfos { get; set; }
        public DbSet<DeepProcessingInfo> DeepProcessingInfos { get; set; }
        public DbSet<UserInfo> UserInfos { get; set; }
        
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.AddInterceptors(_auditableEntitySaveChangesInterceptor);
            base.OnConfiguring(optionsBuilder);
        }
    }
}
